package com.gator.desig_mode.itrator;

import java.util.Iterator;
import java.util.List;
import java.util.function.Consumer;

/**
 * @author 何章怀晓 hezhanghuaixiao
 * @describe 信息学院迭代器，针对信息学院
 * @return
 * @date 2022/3/15  22:29
 * @other
 */

public class InfoCollageIterator implements Iterator {

  public InfoCollageIterator(Department[] departmentList) {
    this.departmentList = departmentList;
  }

  //
  private Department[] departmentList;

  private int position = 0;


  @Override
  public boolean hasNext() {
    System.out.println(position);
    if (departmentList[position] == null || position >= departmentList.length -1 ) {
      return false;
    }
    return true;
  }

  @Override
  public Object next() {
    Department department = departmentList[position];
    System.out.println(department.toString());
    position++;
    return department;
  }



  //

}

//计算机学院迭代器

class ComputerCollageIterator implements Iterator {

  public ComputerCollageIterator(List<Department> departmentList) {
    this.departmentList = departmentList;
  }

  public ComputerCollageIterator(){

  }

  private int position = 0;

  //
  private List<Department> departmentList;


  @Override
  public boolean hasNext() {
    System.out.println(position);
    if (position >= departmentList.size()
        || departmentList.get(position) == null) {
      return false;
    }

    return true;
  }

  @Override
  public Object next() {
    Department department = departmentList.get(position);
    System.out.println(department.toString());
    position++;

    return department;
  }

}
